From e6955d7a3e5ac419c9a5d67c6f6e361c6ae157aa Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Fri, 30 Sep 2005 23:27:06 +0000 Subject: [PATCH] add list code for lan/wan dns SVN-Revision: 2013 --- .../webif/files/usr/lib/webif/form.awk | 2 +- .../webif/files/usr/lib/webif/webif.sh | 22 +++++++++----- .../webif/files/www/cgi-bin/webif/lan.sh | 24 ++++++++++----- .../webif/files/www/cgi-bin/webif/wan.sh | 29 +++++++++++++++---- .../www/cgi-bin/webif/wireless-config.sh | 8 ++--- 5 files changed, 59 insertions(+), 26 deletions(-) diff --git a/openwrt/package/webif/files/usr/lib/webif/form.awk b/openwrt/package/webif/files/usr/lib/webif/form.awk index 8a405bcb98..b402285000 100644 --- a/openwrt/package/webif/files/usr/lib/webif/form.awk +++ b/openwrt/package/webif/files/usr/lib/webif/form.awk @@ -62,7 +62,7 @@ $1 ~ /^select/ { ($1 ~ /^listedit/) { n = split($4 " ", items, " ") for (i = 1; i <= n; i++) { - if (items[i] != "") print "" items[i] " Remove" + if (items[i] != "") print "" items[i] " Remove" } print "" } diff --git a/openwrt/package/webif/files/usr/lib/webif/webif.sh b/openwrt/package/webif/files/usr/lib/webif/webif.sh index 445b234ec6..43f54b0067 100644 --- a/openwrt/package/webif/files/usr/lib/webif/webif.sh +++ b/openwrt/package/webif/files/usr/lib/webif/webif.sh @@ -181,11 +181,9 @@ list_remove() { BEGIN { RS=" " FS=":" - first = 1 } -($0 !~ /^'"$2"'/) { - if (first != 1) printf " " - printf $0 +($0 !~ /^'"$2"'/) && ($0 != "") { + printf " " $0 first = 0 }' } @@ -194,12 +192,17 @@ handle_list() { _new="${1:+$(list_remove "$LISTVAL" "$1") }" _new="${_new:-$LISTVAL}" LISTVAL="$_new" + LISTVAL="${LISTVAL# }" + LISTVAL="${LISTVAL%% }" _validate="$4" _validate="${4:-none}" - [ \! -z "$3" ] && validate "$_validate|$2" && LISTVAL="$LISTVAL $2" + _changed="$1" + [ \! -z "$3" ] && validate "$_validate|$2" && { + LISTVAL="$LISTVAL $2" + _changed="$1$3" + } - _changed="$1$3" _return="${_changed:+0}" _return="${_return:-255}" LISTVAL="${LISTVAL# }" @@ -221,8 +224,11 @@ save_setting() { mkdir -p /tmp/.webif oldval=$(eval "echo \${$2}") oldval=${oldval:-$(nvram get "$2")} - mv /tmp/.webif/config-$1 /tmp/.webif/config-$1-old 2>&- >&- - grep -v "^$2=" /tmp/.webif/config-$1-old > /tmp/.webif/config-$1 2>&- + grep "^$2=" /tmp/.webif/config-$1 >&- 2>&- && { + mv /tmp/.webif/config-$1 /tmp/.webif/config-$1-old 2>&- >&- + grep -v "^$2=" /tmp/.webif/config-$1-old > /tmp/.webif/config-$1 2>&- + oldval="" + } [ "$oldval" != "$3" ] && echo "$2=\"$3\"" >> /tmp/.webif/config-$1 rm -f /tmp/.webif/config-$1-old } diff --git a/openwrt/package/webif/files/www/cgi-bin/webif/lan.sh b/openwrt/package/webif/files/www/cgi-bin/webif/lan.sh index 9eee53d807..d9fd7759e6 100755 --- a/openwrt/package/webif/files/www/cgi-bin/webif/lan.sh +++ b/openwrt/package/webif/files/www/cgi-bin/webif/lan.sh @@ -3,12 +3,20 @@ . /usr/lib/webif/webif.sh load_settings network -[ -z $FORM_submit ] && { +FORM_dns="${lan_dns:-$(nvram get lan_dns)}" +LISTVAL="$FORM_dns" +handle_list "$FORM_dnsremove" "$FORM_dnsadd" "$FORM_dnssubmit" 'ip|FORM_dnsadd|LAN DNS address|required' && { + FORM_dns="$LISTVAL" + save_setting network lan_dns "$FORM_dns" +} +FORM_dnsadd=${FORM_dnsadd:-192.168.1.1} + + +if [ -z "$FORM_submit" -o \! -z "$ERROR" ]; then FORM_lan_ipaddr=${lan_ipaddr:-$(nvram get lan_ipaddr)} FORM_lan_netmask=${lan_netmask:-$(nvram get lan_netmask)} FORM_lan_gateway=${lan_gateway:-$(nvram get lan_gateway)} - FORM_lan_dns=${lan_dns:-$(nvram get lan_dns)} -} || { +else SAVED=1 validate " ip|FORM_lan_ipaddr|LAN IP|required|$FORM_lan_ipaddr @@ -17,9 +25,8 @@ ip|FORM_lan_gateway|LAN gateway||$FORM_lan_gateway" && { save_setting network lan_ipaddr $FORM_lan_ipaddr save_setting network lan_netmask $FORM_lan_netmask save_setting network lan_gateway $FORM_lan_gateway - save_setting network lan_dns $FORM_lan_dns } -} +fi header "Network" "LAN" "LAN settings" '' "$SCRIPT_NAME" @@ -30,8 +37,11 @@ field|Netmask text|lan_netmask|$FORM_lan_netmask field|Default Gateway text|lan_gateway|$FORM_lan_gateway -field|DNS Server -text|lan_dns|$FORM_lan_dns +end_form +start_form|DNS Servers +listedit|dns|$SCRIPT_NAME?|$FORM_dns|$FORM_dnsadd +helpitem|Note +helptext|You should save your settings on this page before adding/removing DNS servers end_form" footer ?> diff --git a/openwrt/package/webif/files/www/cgi-bin/webif/wan.sh b/openwrt/package/webif/files/www/cgi-bin/webif/wan.sh index c9a64691e9..60a930de29 100755 --- a/openwrt/package/webif/files/www/cgi-bin/webif/wan.sh +++ b/openwrt/package/webif/files/www/cgi-bin/webif/wan.sh @@ -4,6 +4,15 @@ load_settings network +FORM_dns="${wan_dns:-$(nvram get wan_dns)}" +LISTVAL="$FORM_dns" +handle_list "$FORM_dnsremove" "$FORM_dnsadd" "$FORM_dnssubmit" 'ip|FORM_dnsadd|WAN DNS address|required' && { + FORM_dns="$LISTVAL" + save_setting network wan_dns "$FORM_dns" +} +FORM_dnsadd=${FORM_dnsadd:-192.168.1.1} + + [ -z $FORM_submit ] && { FORM_wan_proto=${wan_proto:-$(nvram get wan_proto)} case "$FORM_wan_proto" in @@ -27,7 +36,6 @@ text|pptp_server_ip|$FORM_pptp_server_ip" FORM_wan_ipaddr=${wan_ipaddr:-$(nvram get wan_ipaddr)} FORM_wan_netmask=${wan_netmask:-$(nvram get wan_netmask)} FORM_wan_gateway=${wan_gateway:-$(nvram get wan_gateway)} - FORM_wan_dns=${wan_dns:-$(nvram get wan_dns)} # ppp common FORM_ppp_username=${ppp_username:-$(nvram get ppp_username)} @@ -76,7 +84,6 @@ ip|FORM_pptp_server_ip|PPTP server IP|$V_PPTP|$FORM_pptp_server_ip" && { # Settings specific to one protocol type case "$FORM_wan_proto" in static) - save_setting network wan_dns $FORM_wan_dns save_setting network wan_gateway $FORM_wan_gateway ;; pptp) @@ -121,6 +128,7 @@ function modechange() { var v; v = (checked('wan_proto_pppoe') || checked('wan_proto_pptp')); + set_visible('ppp_settings', v); set_visible('ppp_username', v); set_visible('ppp_passwd', v); set_visible('ppp_redial', v); @@ -129,6 +137,7 @@ function modechange() set_visible('ppp_persist_redialperiod', v && !checked('ppp_redial_demand')); v = (checked('wan_proto_static') || checked('wan_proto_pptp') || checked('wan_proto_dhcp')); + set_visible('ip_settings', v); set_visible('wan_ipaddr', v); set_visible('wan_netmask', v); @@ -145,17 +154,25 @@ radio|wan_proto|$FORM_wan_proto|dhcp|DHCP
|onchange=\"modechange()\" radio|wan_proto|$FORM_wan_proto|static|Static IP
|onchange=\"modechange()\" $PPPOE_OPTION $PPTP_OPTION +end_form +start_form|IP Settings|ip_settings|hidden field|Internet IP Address|wan_ipaddr|hidden text|wan_ipaddr|$FORM_wan_ipaddr field|Subnet Mask|wan_netmask|hidden text|wan_netmask|$FORM_wan_netmask field|Gateway|wan_gateway|hidden text|wan_gateway|$FORM_wan_gateway -field|DNS Server(s)|wan_dns|hidden -text|wan_dns|$FORM_wan_dns $PPTP_SERVER_OPTION +end_form + +start_form|DNS Servers|wan_dns|hidden +listedit|dns|$SCRIPT_NAME?wan_proto=static&|$FORM_dns|$FORM_dnsadd +helpitem|Note +helptext|You should save your settings on this page before adding/removing DNS servers +end_form +start_form|PPP Settings|ppp_settings|hidden field|PPP Redial Policy|ppp_redial|hidden radio|ppp_redial|$FORM_ppp_redial|demand|Connect on Demand
|onChange=\"modechange()\" radio|ppp_redial|$FORM_ppp_redial|persist|Keep Alive|onChange=\"modechange()\" @@ -169,9 +186,9 @@ field|PPP Password|ppp_passwd|hidden text|ppp_passwd|$FORM_ppp_passwd field|PPP MTU|ppp_mtu|hidden text|ppp_mtu|$FORM_ppp_mtu -end_form" ?> +end_form" - +footer ?> diff --git a/openwrt/package/webif/files/www/cgi-bin/webif/wireless-config.sh b/openwrt/package/webif/files/www/cgi-bin/webif/wireless-config.sh index ddc44f62a1..17d90a763f 100755 --- a/openwrt/package/webif/files/www/cgi-bin/webif/wireless-config.sh +++ b/openwrt/package/webif/files/www/cgi-bin/webif/wireless-config.sh @@ -3,13 +3,11 @@ . /usr/lib/webif/webif.sh load_settings "wireless" - FORM_wds="${wl0_wds:-$(nvram get wl0_wds)}" LISTVAL="$FORM_wds" handle_list "$FORM_wdsremove" "$FORM_wdsadd" "$FORM_wdssubmit" 'mac|FORM_wdsadd|WDS MAC address|required' && { FORM_wds="$LISTVAL" save_setting wireless wl0_wds "$FORM_wds" - FORM_submit="" } FORM_wdsadd=${FORM_wdsadd:-00:00:00:00:00:00} @@ -24,7 +22,7 @@ for ch in $CHANNELS; do " done -if [ -z "$FORM_submit" ]; then +if [ -z "$FORM_submit" -o \! -z "$ERROR" ]; then FORM_mode=${wl0_mode:-$(nvram get wl0_mode)} FORM_ssid=${wl0_ssid:-$(nvram get wl0_ssid)} FORM_channel=${wl0_channel:-$(nvram get wl0_channel)} @@ -226,7 +224,9 @@ radio|key|$FORM_key|4 text|key4|$FORM_key4|
end_form start_form|WDS connections -listedit|wds|$SCRIPT_NAME|$FORM_wds|$FORM_wdsadd +listedit|wds|$SCRIPT_NAME?|$FORM_wds|$FORM_wdsadd +helpitem|Note +helptext|You should save your settings on this page before adding/removing WDS links end_form" footer ?> -- 2.30.2